home *** CD-ROM | disk | FTP | other *** search
- /* File: AppleEventHandlers.c */
- #include "AEObjects.h"
- #include "AEPackObject.h"
- #include "AERegistry.h"
- #include "ScriptScrap.h"
- #include "Prototypes.h"
-
-
- void InstallAppleEventHandlers(void)
- {
- OSErr err;
- long result;
-
- err = Gestalt(gestaltAppleEventsAttr, &result);
- if ((err == noErr) && (result & 1)) {
- err = AEObjectInit();
-
- (void)AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, (EventHandlerProcPtr)HandleOapp, 0, false);
- (void)AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, (EventHandlerProcPtr)HandleOdoc, 0, false);
- (void)AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, (EventHandlerProcPtr)HandlePdoc, 0, false);
- (void)AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (EventHandlerProcPtr)HandleQuit, 0, false);
-
- /* This is a "catch-all" for debugging -- it reports if an event wasn't handled */
- (void)AEInstallEventHandler(typeWildCard, typeWildCard, (EventHandlerProcPtr)NotHandled, 0, false);
-
- /* Install our event handlers for Object Model Apple Events */
- (void)AEInstallEventHandler(kAECoreSuite, typeWildCard, (EventHandlerProcPtr)DirectParamDispatch, 0, false);
- (void)AEInstallEventHandler(kAECoreSuite, kAECreateElement, (EventHandlerProcPtr)CreateElementDispatch, 0, false);
- /* Install the object accessors for use with the Object Support Library */
- (void)AEInstallObjectAccessor('prop', typeNull, (accessorProcPtr)PropertyFromNullAccessor, 0, false);
-
- (void)AEInstallObjectAccessor(cWindow, typeNull, (accessorProcPtr)WindowFromNullAccessor, 0, false);
- (void)AEInstallObjectAccessor(cDocument, typeNull, (accessorProcPtr)WindowFromNullAccessor, 0, false);
- (void)AEInstallObjectAccessor(typeProperty, cDocument, (accessorProcPtr)PropertyFromWindowAccessor, 0, false);
- (void)AEInstallObjectAccessor(typeProperty, typeNull, (accessorProcPtr)PropertyFromNullAccessor, 0, false);
-
- (void)AEInstallObjectAccessor(cEntry, cDocument, (accessorProcPtr)EntryFromDocumentAccessor, 0, false);
- (void)AEInstallObjectAccessor(cScrapItem, cEntry, (accessorProcPtr)ItemFromEntryAccessor, 0, false);
- (void)AEInstallObjectAccessor(typeProperty, cEntry, (accessorProcPtr)PropertyFromEntryAccessor, 0, false);
- (void)AEInstallObjectAccessor(typeProperty, cScrapItem, (accessorProcPtr)PropertyFromItemAccessor, 0, false);
- }
- } /* init_apple_events_hook */
-
-
- char *OSTypeToPStr(OSType theType, char *s)
- /* This is a useful debugging tool as it allows us to put an EventID or EventID */
- /* into a string so we can display it in a dialog */
- {
- *s = 0x04;
- BlockMove(&theType, &s[1], 4); /* Use BlockMove to avoid odd address error on 68000 machines */
- return s;
- }
-
- pascal OSErr NotHandled (AEDescList *aevt, AEDescList *reply, long refCon)
- /* This routine is called for any unknown events that come in (it's installed into the */
- /* table with wild-card handlers) and it will put up a dialog that lets us know that a */
- /* "bad" Apple event has come in. */
- {
- OSErr err;
- OSType eventClass, eventID;
- OSType typeCode;
- char scratchClass[5], scratchID[5];
- Size actualSize;
- short itemHit;
-
- AEDesc directParam;
-
-
- err = MyInteractWithUser(TRUE); /* Tell the user it's urgent */
- if (err == noErr) {
- AEGetAttributePtr(aevt, keyEventClassAttr, typeType, &typeCode, (Ptr)&eventClass, sizeof(eventClass), &actualSize);
- AEGetAttributePtr(aevt, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID, sizeof(eventID), &actualSize);
- ParamText((void *)OSTypeToPStr(eventClass, scratchClass), (void *)OSTypeToPStr(eventID, scratchID), (void *)"", (void *)"");
- itemHit = Alert(1002, 0L);
- }
- return errAEEventNotHandled;
- } /* NotHandled */
-
-
- pascal OSErr HandleOapp (AEDescList *aevt, AEDescList *reply, long refCon)
- {
- /* Find the standard Scrapbook File and open it */
- /* It's called "Scrapbook file" and is located in the System folder */
-
- OSErr err;
- FSSpec scrapbookFile;
- Str63 fileName = "\pScrapbook File";
-
- /* Locate the system folder */
- err = FindFolder(kOnSystemDisk,kSystemFolderType,false, &scrapbookFile.vRefNum, &scrapbookFile.parID);
- if (err == noErr) {
- /* Set the file's name to "Scrapbook file" */
- BlockMove(fileName, &scrapbookFile.name, fileName[0] + 1);
- /* Open a window containing this file */
- err = NewDisplayWindow(&scrapbookFile);
- }
- return err;
- } /* NotHandled */
-
-
- pascal OSErr HandleOdoc (AEDescList *aevt, AEDescList *reply, long refCon)
- {
- AEDesc fileListDesc;
- long numFiles;
- DescType actualType;
- long actualSize;
- AEKeyword actualKeyword;
- FSSpec oneFile;
- long index;
- OSErr err;
-
- /* The "odoc" and "pdoc" messages contain a list of aliases as the direct paramater. */
- /* This means that we'll need to extract the list, count the list's elements, and */
- /* then process each file in turn. */
-
- /* Extract the list of aliases into fileListDesc */
- err = AEGetKeyDesc( aevt, keyDirectObject, typeAEList, &fileListDesc );
- if (err) return err;
-
- /* Count the list elements */
- err = AECountItems( &fileListDesc, &numFiles);
- if (err) return err;
-
- /* now get each file from the list and process it. */
- /* Even though the event contains a list of alises, the Apple Event Manager */
- /* will convert each alias to an FSSpec if we ask it to. */
- for (index = 1; index <= numFiles; index ++) {
- err = AEGetNthPtr( &fileListDesc, index, typeFSS, &actualKeyword,
- &actualType, (Ptr)&oneFile, sizeof(oneFile), &actualSize);
- if (err) {
- AEDisposeDesc(&fileListDesc );
- return err;
- }
-
- NewDisplayWindow(&oneFile);
- }
- return noErr;
- } /* HandleOdoc */
-
-
- pascal OSErr HandlePdoc (AEDescList *aevt, AEDescList *reply, long refCon)
- {
- return errAEEventNotHandled; /* We don't do printing… */
- } /* HandlePdoc */
-
-
- pascal OSErr HandleQuit (AEDescList *aevt, AEDescList *reply, long refCon)
- {
- gDone = TRUE;
- return noErr;
- } /* NotHandled */
-